<?php
// +----------------------------------------------------------------------
// | quanli team
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2020 http://www.fistforward.com/ All rights reserved.
// +----------------------------------------------------------------------
// | create by allen.qiang
// +----------------------------------------------------------------------

/**
 * 领奖纪录ajax类
 * @package  	ajax
 * @subpackage  backend
 * @create by allen.qiang
 */

quanli_require('module/base/promotionHandler.class.php');
class ajax_awardRecord {

    public function execute(){

        if (isset($_REQUEST['operFlg']) && $_REQUEST['operFlg'] > 0) {

            switch($_REQUEST['operFlg']) {

                case 1: //领奖纪录列表
                    $this->awardRecordList();
                    break;
                case 2:
                    $this->awardRecordEdit();
                    break;
                case 3:
                    $this->getAwardRecord();
                    break;
                default:
                    $this->toReturn('参数错误');
                    break;

            }

        } else {

            $this->toReturn('参数错误');

        }

    }

    /**
     * 返回信息
     * @param string $message
     * @param int $code
     * @param mixed $data
     */
    private function toReturn( $message, $code = 400, $data = '' ) {

        die( json_encode( array( 'code' => $code, 'message' => $message, 'data' => $data ) ) );

    }

    //领奖纪录列表
    private function awardRecordList(){
        global $G_PGLOB;

        $promotionHandler = new promotionHandler($G_PGLOB->DBCA);

        $arg_array = $_REQUEST;

        $result_data = $promotionHandler->awardRecordList($arg_array);

        $result_array = array(
            'page'  => $arg_array['page'] ,
            'total' => $arg_array['count'] ,
            'rows'  => array()
        );


        if ($result_data) {

            $edit_permission = $G_PGLOB->has_permission(4523);

            foreach($result_data as $val) {

                if($edit_permission){

                    $result_array['rows'][] = array(
                        'id' 	=> $val['receive_id'],
                        'cell' 	=> array(
                            '<a  href="javascript: void(0);" onclick="award.openHTML.awardEdit('.$val['receive_id'].')">修改</a>',
                            $val['custName'],
                            $val['mobile'],
                            $val['address'],
                            $val['identityCard'],
                            $val['prize'],
                            $val['createTime']
                        ),
                    );

                }else{

                    $result_array['rows'][] = array(
                        'id' 	=> $val['pcustID'],
                        'cell' 	=> array(
                            $val['custName'],
                            $val['mobile'],
                            $val['address'],
                            $val['identityCard'],
                            $val['prize'],
                            $val['createTime']
                        ),
                    );

                }
            }
        }

        echo json_encode( $result_array );


    }

    private function awardRecordEdit(){

        global $G_PGLOB;

        $promotionHandler = new promotionHandler($G_PGLOB->DBCA);

        $arg_array = $_REQUEST['dt'];

        $result_data = $promotionHandler->awardRecordEdit($arg_array);

        echo json_encode($result_data);

    }

    private function getAwardRecord(){

        global $G_PGLOB;

        $promotionHandler = new promotionHandler($G_PGLOB->DBCA);

        $arg_array = $_REQUEST;

        $receive_prize = $promotionHandler->awardRecordList($arg_array);

        echo json_encode($receive_prize[0]);

    }
}
